{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9e998aba",
   "metadata": {},
   "outputs": [],
   "source": [
    "file = './dbscripts/1_table.sql'  # Replace with your file name\n",
    "file2 = './dbscripts/2_data.sql'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ba65e884",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(file, 'rb') as f:\n",
    "    bom = f.read(3)\n",
    "    if bom == b'\\xef\\xbb\\xbf':  # UTF-8 BOM 的字节表示\n",
    "        print(\"文件包含 UTF-8 BOM\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "99c46c60",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(file, 'r', encoding='utf-8-sig') as f:\n",
    "    content = f.read()\n",
    "with open('converted_file.sql', 'w', encoding='utf-8') as f:\n",
    "    f.write(content)  # 去除 BOM，保存为纯 UTF-8"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
